export class nl extends plugin {
  constructor() {
    super({
      name: "多源动漫图",
      dsc: "七API源随机动漫图片",
      event: "message",
      priority: 5000,
      rule: [{
        reg: "^#随机好图$",
        fnc: "getImg"
      }]
    })
  }

  async getImg() {
    try {
      const apis = [
        { source: "yimian", url: "https://api.yimian.xyz/img?type=moe", parse: r => r.json().then(d => d.img) },
        { source: "paugram", url: "https://api.paugram.com/wallpaper/", parse: r => r.json().then(d => d.url) },
        { source: "yuanxiapi", url: "http://yuanxiapi.cn/api/img/?type=dongman", parse: r => r.json().then(d => d.img) },
        { source: "mtyqx", url: "https://api.mtyqx.cn/tapi/random.php", parse: r => r.url },
        { source: "ixiaowai", url: "https://api.ixiaowai.cn/api/api.php", parse: r => r.url },
        { source: "dmoe", url: "https://www.dmoe.cc/random.php", parse: r => r.json().then(d => d.acgurl) },
        { source: "btstu", url: "https://api.btstu.cn/sjbz/api.php?lx=dongman", parse: r => r.url }
      ]

      const success = await Promise.any(apis.map(async ({ source, url, parse }) => {
        const res = await fetch(url)
        if (!res.ok) throw new Error(`${source}请求失败`)
        return parse(res)
      }))

      this.reply(segment.image(success))
    } catch {
      this.reply("所有接口都挂了，晚点再试吧 (＞﹏＜)")
    }
  }
}